package edu.cmu.ece.ds.droidchat;

import java.util.ArrayList;

import android.app.ListActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import edu.cmu.ece.ds.droidchat.controller.ChatSessionListBaseAdapter;
import edu.cmu.ece.ds.droidchat.model.ChatSessionInfo;

public class ChatSessionsListActivity extends ListActivity {

    static final String[] DEMO_CHAT_SESSIONS = new String[] { "Apple",
            "Banana", "Clementine", "Durian" };

    private ArrayList<ChatSessionInfo> mChatSessionArray;

    private ChatSessionListBaseAdapter mChatSessionListBaseAdapter;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // the demo array
        mChatSessionArray = new ArrayList<ChatSessionInfo>();
        ChatSessionInfo a = new ChatSessionInfo("Pending Apple", null);
        a.setChatSessionName("Pending Apple");
        mChatSessionArray.add(a);
        a = new ChatSessionInfo("Pending Banana", null);
        a.setChatSessionName("Pending Banana");
        mChatSessionArray.add(a);
        a = new ChatSessionInfo("Available Clementine", null);
        a.setChatSessionName("Available Clementine");
        a.setPending(false);
        mChatSessionArray.add(a);
        mChatSessionListBaseAdapter = new ChatSessionListBaseAdapter(this,
                mChatSessionArray);

        setListAdapter(mChatSessionListBaseAdapter);

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setDivider(null);
        lv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        lv.setCacheColorHint(Color.WHITE);

        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                TextView tv = (TextView) ((LinearLayout) view)
                        .findViewById(R.id.chat_session_name);
                // When clicked, show a toast with the TextView text
                Toast.makeText(getApplicationContext(), tv.getText(),
                        Toast.LENGTH_SHORT).show();
            }
        });
    }
}
